/**
 * @file pagination.js
 * @author wxf
 * @date 2018/5/30
 */
var trs=$("#lsw tr");
var pageSize=5;
var curr=1;
var currRow=pageSize*curr;
var allPage=Math.ceil(trs.length/pageSize);
var currRow=pageSize*curr;

//页面初始状态 显示第一页的内容
$(document).ready(function(){
  hideTab();
  curr=1;
  var currRow=pageSize*curr;
  $.each(trs,function(index,value){
    if(index<currRow&&index>=currRow-pageSize){
      this.style.display="";
      // {#$('#first').css({'width':'1200px'});#}
      // {#$('#second').css({'width':'200px'});#}
      // {#$('#third').css({'width':'200px'});#}
      // {#$('#fourth').css({'width':'200px'});#}
      // {#$('#fifth').css({'width':'800px'});#}
      // {#$('#sixth').css({'width':'200px'});#}
    }
    });

  // {#$("#lsw tr:lt(3)").css("display","block");#}
  $("#spanTotalPage").text(allPage);
  $("#spanPageNum").text(curr);
  $("#count").css({"width":"20px","border-radius":"5px"});
  });


//通用隐藏方法
function hideTab(){
  trs.css("display","none");
  }
  //为下一页 绑定点击事件
function spanNext(){
  hideTab();
  if(curr>allPage-1){
    curr=allPage;
    }else{
      curr++;
    }
    var currRow=pageSize*curr;
  $.each(trs,function(index,value){
    if(index<currRow&&index>=currRow-pageSize){
      var that=this;
      that.style.display="";
      }
      });
  $("#spanPageNum").text(curr);
  }
  $("#spanNext").bind("click",spanNext);


//为上一页 绑定点击事件
function spanPre(){
  hideTab();
  if(curr<2){
    curr=1;
    }else{
    curr--;
    }
    var currRow=pageSize*curr;
  $.each(trs,function(index,value){
    if(index<currRow&&index>=currRow-pageSize){
      var that=this;
      that.style.display="";
      }
      });
  $("#spanPageNum").text(curr);
  }
  $("#spanPre").bind("click",spanPre);

//为第一页绑定点击事件
function spanFirst(){
  hideTab();
  curr=1;
  var currRow=pageSize*curr;
  $.each(trs,function(index,value){
    if(index<currRow&&index>=currRow-pageSize){
      this.style.display="";

      }
      });

  $("#spanPageNum").text(curr);
  }
  $("#spanFirst").bind("click",spanFirst);


//为最后一页绑定点击事件
function spanLast(){
  hideTab();
  curr=allPage;
  var currRow=pageSize*curr;
  $.each(trs,function(index,value){
    if(index<currRow&&index>=currRow-pageSize){
      this.style.display="";

      }
      });
  $("#spanPageNum").text(curr);
  }
  $("#spanLast").bind("click",spanLast);

//手动输入input值变化
//为btn绑定 点击按钮刷新事件

$("#btn").click(function(){
  if ($("#count").val().trim() ==""){
    spanFirst();
    }else if($("#count").val()>=1&&$("#count").val()<=allPage){
    hideTab();
    curr=$("#count").val();
    var currRow=pageSize*curr;
    $.each(trs,function(index,value){
      if(index<currRow&&index>=currRow-pageSize){
        this.style.display="";
        }
        });
    $("#spanPageNum").text(curr);
    }else{
    alert("超出页数范围 或者 输入有误 \n请输入正确页码");
    $('#count').val("");
    return false;
    }
    });
